package com.kgc.server.service.Impl;

import com.kgc.server.dao.IndexDao;
import com.kgc.server.pojo.EasyBuyNews;
import com.kgc.server.pojo.Page;
import com.kgc.server.service.IndexService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("indexService")
public class IndexServiceImpl implements IndexService {
    Logger logger = Logger.getLogger(getClass());
    @Autowired
    private IndexDao indexDao;

    public List getEasybuy_product_categoryList(){
        logger.info("getEasybuy_product_categoryList start...");
        List list = indexDao.getEasybuy_product_categoryList();
        logger.info("getEasybuy_product_categoryList list:"+list);
        return list;
    }
    @Override
    public List getNewsList(){
        logger.info("getNewsList start...");
        return indexDao.getNewsList();
    }

    @Override
    public List getinformationListFy(Page page) {
        logger.info("getinformationListFy page:"+page);
        int num = indexDao.getNewsCount();
        logger.info("getinformationListFy page:"+page+",num:"+num);
        page.setCount(num);
        if( page.getCount() % page.getPageSize() == 0 ){
            page.setPageCount(page.getCount() / page.getPageSize());
        }else{
            page.setPageCount(page.getCount() / page.getPageSize() + 1);
        }
        page.setNum((page.getPageNo()-1)*page.getPageSize());
        logger.info("getinformationListFy page:"+page+",num:"+num);
        return indexDao.getinformationListFy(page);
    }

    @Override
    public int delInformationListById(int id) {
        logger.info("delInformationListById id:"+id);
        int num = indexDao.delInformationListById(id);
        logger.info("delInformationListById id:"+id+",num:"+num);
        return num;
    }

    @Override
    public List getInformation(int id) {
        logger.info("getInformation id:"+id);
        List list = indexDao.getInformation(id);
        logger.info("getInformation id:"+id+",list:"+list);
        return list;
    }

    @Override
    public int updataInformationById(EasyBuyNews easyBuyNews){
        logger.info("updataInformationById easyBuyNews:"+easyBuyNews);
        int num = indexDao.updataInformationById(easyBuyNews);
        logger.info("updataInformationById easyBuyNews:"+easyBuyNews+",num:"+num);
        return num;
    }
}
